<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
		<!-- Loading Bootstrap -->
		<link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
		<!-- Loading Flat UI -->
		<link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
		<!--<link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">-->
		<link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
		<!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
		<!--[if lt IE 9]>
		<script src="dist/js/vendor/html5shiv.js"></script>
		<script src="dist/js/vendor/respond.min.js"></script>
		<![endif]-->
	<!--上传文件-->
		<!-- 需要载入的文件 -->
   		<script type="text/javascript" src="./Public/Admin/uploadify/jquery-1.8.2.min.js"></script>
    	<script type="text/javascript" src="./Public/Admin/uploadify/jquery.uploadify.min.js"></script>
  		<link rel="stylesheet" type="text/css" href="./Public/Admin/uploadify/uploadify.css">
   	<!--引百度编辑器-->
    	<!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="./Public/Admin/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="./Public/Admin/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="./Public/Admin/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
 <!--属性规格--> 		
  <script type="text/javascript">
  	$(function(){
  		$("select[name=category_cid]").change(function(){
//			alert();
			var tid = $("option:selected").attr('tid');
			$('#type_tid').val(tid);
//			console.log(tid);
			$.ajax({
				type:"post",
				url:"{{U('Goods/getAttr')}}",
				data:{t : tid},
				dataType:'json',
				success:function(phpData){
//					console.log(phpData);
//					属性
					var attr = '';
//					规格
					 var spec = '';
					 $.each(phpData, function(k,v) {
					 	//如果是属性
					 	if(v.class == 0 ){
//					 		组装
							attr += '<tr class="info">';
							attr += '<td>'+v.taname+'</td>';
							attr +=	'<td>';
							attr +=	'<select name="attr['+v.taid+']" class="form-control">';
								attr +=	'<option value="">-请选择-</option>';
										$.each(v.tavalue,function(kk,vv) {
											attr +=	'<option value="'+vv+'" >'+vv+'</option>';
										});
								attr +=	'</select>';
								attr += '</td></tr>';
					 	}else{//如果是规格
					 		spec += '<tr class="info">';
							spec +=	'<td>'+v.taname+'</td>';
							spec +=	'<td>';
							spec +=	'<select name="spec[value]['+v.taid+'][]" class="form-control">';
							spec +=	'<option value="">-请选择-</option>';
								$.each(v.tavalue, function(kk,vv) {
									spec +=	'<option value="'+vv+'">'+vv+'</option>';
								});
							spec +=	'</select></td>';
							spec +=	'<td><input placeholder="附加价格" class="form-control" type="text" name="spec[added]['+v.taid+'][]" /></td>';
							spec +=	'<td>';
							spec +=	'<a href="javascript:;" class="btn btn-primary addSpec">添加规格</a>';
							spec += '</td></tr>';
					 	}
					 	
					 });
					$('#attr').html(attr);
					$('#spec').html(spec);
				}
			});
  		})
  		$(".addSpec").live('click',function(){
			//找到当前的父级tr
			var trObj = $(this).parents('tr');
			//克隆一个按钮(删除规格)
			var tr = trObj.clone();
			tr.find('.addSpec').html('删除规格').removeClass('btn-primary addSpec').addClass('btn-info removeSpec');
			//在插入到当前父级下面
			trObj.after(tr);
		})
//		删除
		$(".removeSpec").live('click',function(){
			$(this).parents('tr').remove();
		})
  	})
  </script>  		
	</head>
	<body>
		<form action="" method="post">
			<div class="alert alert-success">
				修改商品
			</div>
			<table class="table table-bordered table-hover">
				<tr>
					<p class="btn btn-primary">基本信息</p>
				</tr>
				<tr class="info">
					<td>所属分类</td>
					<td>
						<select name="category_cid" class="form-control">
							<option value="0">-请选择-</option>
								{{foreach from="$cateData" value="$v"}}
									<option {{if value="$v['cid'] eq $goodsData['category_cid']"}}selected="selected" {{endif}} value="{{$v['cid']}}" tid = {{$v['type_tid']}}>{{$v['_name']}}</option>
								{{endforeach}}
						</select>
						
					</td>
				</tr>
				<tr class="info">
					<td>所属品牌</td>
					<td>
						<select name="brand_bid" class="form-control">
							<option value="0">-请选择-</option>
								{{foreach from="$brandData" value="$v"}}
									<option {{if value="$v['bid'] eq $goodsData['brand_bid']"}} selected="selected" {{endif}} value="{{$v['bid']}}">{{$v['bname']}}</option>
								{{endforeach}}		
						</select></td>
				</tr>
				<tr class="info">
					<td>商品名称</td>
					<td>
						<input class="form-control" type="text" name="shopname" id="shopname" value="{{$goodsData['shopname']}}" />
					</td>
				</tr>
				<tr class="info">
					<td>商品介绍</td>
					<td>
						<input class="form-control" type="text" name="introduction" value="{{$goodsData['introduction']}}" />
					</td>
				</tr>
				<tr class="info">
					<td>单位</td>
					<td>
						<input class="form-control" type="text" name="unit" id="unit" value="{{$goodsData['unit']}}" />
					</td>
				</tr>
				<tr class="info">
					<td>市场价</td>
					<td>
						<input class="form-control" type="text" name="marketprice" id="marketprice" value="{{$goodsData['marketprice']}}" />
					</td>
				</tr>
				<tr class="info">
					<td>商城价</td>
					<td>
						<input class="form-control" type="text" name="shopprice" id="shopprice" value="{{$goodsData['shopprice']}}" />
					</td>
				</tr>
				<tr class="info">
					<td>点击次数</td>
					<td>
						<input class="form-control" type="text" name="click" id="click" value="{{$goodsData['click']}}" />
					</td>
				</tr>
			</table>
			<p class="btn btn-primary">商品属性</p>
			<table border="1" class="table table-bordered table-hover" id="attr">
				{{foreach from="$goodsAttrData" value='$v'}}
					{{if value="$v['class'] eq 0"}}	
				<tr class="info">
					<td>{{$v['taname']}}</td>
					<td>
					<select name="attr[{{$v['taid']}}]" class="form-control">
						<option value="">-请选择-</option>
							{{foreach from="$v['tavalue']" value="$u"}}
								<option {{if value="$v['gtvalue'] eq $u"}}selected{{endif}} value="{{$u}}">{{$u}}</option>
							{{endforeach}}
						</select>
					</td></tr>
						{{endif}}
					{{endforeach}}
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table border="1" class="table table-bordered table-hover" id="spec">
				{{foreach from="$goodsAttrData" value="$v"}}
					{{if value="$v['class'] eq 1"}}
					<?php 
						$taid[]=$v['taid'];
					?>
				<tr class="info">
							<td>{{$v['taname']}}</td>
							<td>
							<select name="spec[value][{{$v['taid']}}][]" class="form-control">
							<option value="">-请选择-</option>
								{{foreach from="$v['tavalue']" value="$u"}}
									<option {{if value="$v['gtvalue'] eq $u"}}selected{{endif}} value="{{$u}}">{{$u}}</option>
								{{endforeach}}	
							</select></td>
							<td><input placeholder="附加价格" class="form-control" type="text" name="spec[added][{{$v['taid']}}][]" value="{{$v['added']}}"/></td>
							<td>
							<a href="javascript:;" class="btn btn-info removeSpec goodsAttr{{$v['taid']}}">删除规格</a>
							</td></tr>
						{{endif}}	
					{{endforeach}}
			</table>
			<?php 
			//去除重复的taid
			$taid = array_unique($taid);
			?>
			<script type="text/javascript">
//				把taid转化为对象格式
				var taid = '<?php echo json_encode($taid) ?>'
				//把js字符串转化为json对象
				taid = $.parseJSON(taid);
				//循环json
				$.each(taid, function(k,v) {
					$('.goodsAttr' + v).first().removeClass('btn btn-info removeSpec').addClass('btn btn-primary addSpec').html('添加规格');
				});
			</script>
			<table border="1" class="table table-bordered">
				<tr>
					<p class="btn btn-primary">列表图</p>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
<!--上传文件--插件begin-->
<!-- html页面 -->
<div lab="uploadFile">
	<!-- file表单 -->
    <input id="f" type="file" multiple="true">
    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
    <script type="text/javascript">
        $(function() {
            $('#f').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '{{__PUBLIC__}}/Admin/uploadify/uploadify.swf',
                'uploader' : '{{U('upload')}}',//指定服务器上传的方法
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 1,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
                    //把php返回的数据转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li>";
                    li += "<img src='"+imageUrl+"'/>";
                    li += "<input type='hidden' name='pic' value='"+data.path+"'/><a href='javascript:;' id='self-close'>X</a>";
                    li += "</li>";
                    $("#uploadList ul").prepend(li);
                }
            });

			//关闭图片
            var i = 1;
            $('#self-close').live('click',function(){
                $(this).parent('li').remove();
                i++;
                $('#f').uploadify('settings','uploadLimit',i);
                attrUrl = $(this).siblings('input').val();
//              alert(attrUrl);
				$.ajax({
						type:"post",
						url:"{{U('Goods/repic')}}",
						data:{attrUrl : url}
					});
            })
        });
    </script>
    <!--<div id="uploadList">
        <ul>

        </ul>
    </div>-->
</div>						
<!--上传文件--插件end-->						
					</td>
<style type="text/css">
	#uploadList ul li img{
		width: 70px;
		height: 50px;
	}
	#uploadList2 ul li img{
		width: 70px;
		height: 50px;
	}
</style>						
					<td id="pic-list">
						<div id="uploadList">
					        <ul>
									<li>
										<img src="{{$goodsData['pic']}}"/>
											<input type='hidden' name='oldpic' value='{{$goodsData['pic']}}'/>
										<a href='javascript:;' id='self-close'>X</a>
									</li>
					        </ul>
					    </div>
					</td>
				</tr>
			</table>
			<table border="1" class="table table-bordered">
				<tr>
					<p class="btn btn-primary">商品 图册</p>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
<!--上传文件--插件begin-->
<!-- html页面 -->
<div lab="uploadFile">
	<!-- file表单 -->
    <input id="f2" type="file" multiple="true">
    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 4</span>
    <script type="text/javascript">
        $(function() {
            $('#f2').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '{{__PUBLIC__}}/Admin/uploadify/uploadify.swf',
                'uploader' : '{{U('uploadifys')}}',//指定服务器上传的方法
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 4,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
                    //把php返回的数据转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li>";
                    li += "<img src='"+imageUrl+"'/>";
                    li += "<input type='hidden' name='images[]' value='"+data.path+"'/><a href='javascript:;' id='self-close'>X</a>";
                    li += "</li>";
                    $("#uploadList2 ul").prepend(li);
                }
            });

			//关闭图片
            var i = 1;
            $('#self-close').live('click',function(){
                $(this).parent('li').remove();
                i++;
                $('#f2').uploadify('settings','uploadLimit',i);
                url = $(this).siblings('input').val();
//              alert($url);
                
					$.ajax({
						type:"post",
						url:"{{U('Goods/reImg')}}",
						data:{url : url}
					});
            })
            
            
        });
    </script>
   
</div>
		
<!--上传文件--插件end-->							
						
					</td>
					<td id="pic-list">
						<div id="uploadList2">
				        <ul>
				        	{{foreach from="$goodsData['images']" value='$u'}}
				        	<li>
					        	<img src="{{$u}}"/>
								<input type='hidden' name='images[]' value='{{$u}}'/>
								<a href='javascript:;' id='self-close'>X</a>
							</li>
							{{endforeach}}	
				        </ul>
				    </div>
					</td>
				</tr>
			</table>
			<table border="1" class="table" style="border: none;">
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
<tr>
<!--调用百度编辑器--begin-->
<script id="editor" type="text/plain" style="width:100%;height:500px;" name="intro">{{$goodsData['intro']}}</script>
<script>
    var ue = UE.getEditor('editor');
</script>						
<!--调用百度编辑器--end-->
</tr>
			</table>
			<input type="hidden" name="type_tid" id="type_tid" value="{{$goodsData['type_tid']}}" />
			<input type="hidden" name="aid" id="aid" value="{{Q('get.aid')}}" />
			<button class="btn btn-primary btn-block" type="submit">
			确认添加
			</button>
		
			
		</form>
	</body>
</html>